jQuery(document).ready(function(){	
	
	//alert("完整的项目名称"+$ctx); 
	show_cur_times();
	//setInterval("show_cur_times()",100); //更新时间
	//获取菜单
	$.ajax({  
		type: "POST",  
        url: $ctx+'SiteIndex/querySiteNav.json', 
        async: false,
	    data:{  
	    	  issue:1,
	    	  parentID:0,
	    	  typeID:0 //顶部导航
	    },  		    	     
	    cache:false,  
	    dataType:'json',  
	    success:function(data) { 
	    	if(data!=null && data.length>0){		    	    		
	    		$.each(data,function(idx,obj){
	    			var addhtml='';
	    			var url=$ctx+obj.url;
	                if(obj.isParent=="true"){
	                	addhtml = '<li id="nav'+obj.id+'" >'+
						  			'<b class="navOverleft"></b><a href="'+url+'" class="navfoucea" >'+obj.menuName+'</a><b class="navOverRight"></b>'+
					  			  '</li>';			    	                	
    	                findSubNav(obj.id);	 //查找二级菜单
	                }else{
	                	addhtml = '<li id="nav'+obj.id+'">'+
		  							'<b class="navOverleft"></b><a href="'+url+'" >'+obj.menuName+'</a><b class="navOverRight"></b>' +
	  				  			  '</li>';	
	                }
	                $("#navfouce").append(addhtml);	
	    		});
	    	}	
	    },  
	     error : function() {  
	            
	     }  
	});
	
	
	//获取头部轮播图片
	$.ajax({  
		type: "POST",  
        url: $ctx+'SiteIndex/querySiteAd.json', 
	    data:{  
	    	  visible:0,
	    	  typeid:5
	    },  		    	     
	    cache:false,  
	    dataType:'json',  
	    success:function(data) { 
	    	if(data!=null && data.length>0){		    	    		
	    		$.each(data,function(idx,obj){
	    			if(obj.filepath!=null && $.trim(obj.filepath)!=''){
	    				var addhtml = '<img src="{0}" />'.format(obj.filepath);		    	    			
		                $("#slider").append(addhtml);
	    			}
	    		});
	    		
	    		$('#slider').nivoSlider({
		        	//manualAdvance:true
		        	 effect: 'random',               // 过渡效果  
		             slices: 15,                     // 切片效果时的数量  
		             boxCols: 8,                     // 格子效果时的列数  
		             boxRows: 4,                     // 格式效果时的行数  
		             animSpeed: 500,                // 图片过渡时间  
		             pauseTime: 10000,                // 图片显示时间  	           
		             directionNav: false,             // 是否显示图片方向切换按钮（上一页/下一页）  
		             controlNav: false,               // 是否显示图片导航控制按钮（,2,3... ）  
		             controlNavThumbs: false,        // 是否使用图片的缩略图做为导航控制按钮  
		             pauseOnHover: true,             // 鼠标县浮时是否停止动画  
		             manualAdvance: false,           // 是否手动切换  	           
		             randomStart: false,             // 开始图片是否随机		          
		        });
	    	}	
	    },  
	     error : function() {  
	            
	     }  
	});	
	
	
	//联系我们
	$.ajax({  
		type: "POST",  
        url: $ctx+'SiteIndex/queryContent.json', 
	    data:{  
	    	tag:'lxwm',
	    	isModule:1 
	    },  		    	     
	    cache:false,  
	    dataType:'json',  
	    success:function(data) { 
	    	if(data!=null && data.length>0){		    	    		
	    		$.each(data,function(idx,obj){
	    			var addhtml =(obj.contents).replace(/\n/g,'<br/>');	    			
	                $(".footer").append(addhtml);		    	                
	    		});
	    	}	
	    },  
	     error : function() {  
	          
	     }  
	});
	
	
	//最新公告
	$.ajax({  
		type: "POST",  
        url: $ctx+'SiteIndex/queryArticle.json', 
	    data:{  
	    	  categoryID:2,	
	    	  topNum:1
	    },  		    	     
	    cache:false,  
	    dataType:'json',  
	    success:function(data) { 
	    	if(data!=null && data.length>0){		    	    		
	    		$.each(data,function(idx,obj){	    			
	    				var maxwidth=25; 
	    				if(obj.title.length>maxwidth){
		    				obj.title=obj.title.substring(0,maxwidth);
		    				obj.title+=' ...'; 
		    			}
	    				
		    			var url=$ctx+'SiteIndex/article.htm?id='+encode64((obj.id).toString());
		    			
		    			var addhtml = '<a target="_blank" style="font-size: 12px; color:#000000"  href="'+url+'">'+obj.title+'</a>';						
		    			$("#newNotice").append(addhtml);    
	    		});
	    		
	    	}	
	    },  
	     error : function() {  
	          
	     }  
	});


});

function findSubNav(parentId){//二级菜单
	$.ajax({  
		type: "POST",  
        url: $ctx+'SiteIndex/querySiteNav.json', 
        async: false,
	    data:{  
	    	  issue:1,
	    	  parentID:parentId,
	    	  typeID:0 //顶部导航
	    },  		    	     
	    cache:false,  
	    dataType:'json',  
	    success:function(data) { 
	    	if(data!=null && data.length>0){		    	    		
	    		var html='<div style="display: none;" id="con'+parentId+'" class="cont"><ul>';
	    		var addhtml='';		    	    		
	    		$.each(data,function(idx,obj){	
	    			var urlNew='';
	    			if(obj.categoryID!=null && obj.categoryID=='1'){ //内容导航
	    				urlNew=$ctx+'SiteIndex/content.htm?fk_menuId='+encode64(String(obj.id))+'&parNav='+parentId;
	    			}else{
	    				if(obj.url!='' && (obj.url).indexOf('http')==-1){
		    				urlNew=$ctx+obj.url;
		    				if(urlNew.indexOf('?')==-1){
		    					urlNew=urlNew+'?parNav='+parentId
		    				}else{
		    					urlNew=urlNew+'&parNav='+parentId
		    				}
		    			}else{
		    				urlNew=obj.url;
		    			}	    				
	    			}
	    			
	    			addhtml += '<li><a target="_blank" href="'+urlNew+'" class="ys">'+obj.menuName+'</a></li>';
	    		});		    	    		
	    		$("#navbox").append(html+addhtml+'</ul></div>');		    	    		
	    	}	
	    },  
	     error : function() {  
	            
	     }  
	});
}



function show_cur_times(){ 
    var show_day=new Array('星期日','星期一','星期二','星期三','星期四','星期五','星期六'); 
    var time=new Date(); 
    var year=time.getFullYear(); 
    var month=time.getMonth()+1; 
    var date=time.getDate(); 
    var day=time.getDay(); 
    var hour=time.getHours(); 
    var minutes=time.getMinutes(); 
    var second=time.getSeconds(); 
  
    month<10?month='0'+month:month; 	            
    hour<10?hour='0'+hour:hour; 
    minutes<10?minutes='0'+minutes:minutes; 
    second<10?second='0'+second:second; 
   
    var now_time=''+year+'年'+month+'月'+date+'日'+' '+show_day[day];
    
    //+' '+hour+':'+minutes+':'+second; 
    document.getElementById('showtimes').innerHTML=now_time; 
}

String.prototype.format = function (args) {
    if (arguments.length > 0) {
        var result = this;
        var reg;
        if (arguments.length == 1 && typeof (args) == "object") {
            for (var key in args) {
                reg = new RegExp("([{]" + key + "[}])", "g");
                result = result.replace(reg, args[key]);
            }
        } else {
            for (var i = 0; i < arguments.length; i++) {
                if (arguments[i] == undefined) {
                    return this;
                } else {
                    reg = new RegExp("([{]" + i + "[}])", "g");
                    result = result.replace(reg, arguments[i]);
                }
            }
        }
        return result;
    } else {
        return this;
    }
};


//格式化日期
Date.prototype.format = function(format) {	
  var o = {
      "M+": this.getMonth() + 1, // month
      "d+": this.getDate(), // day
      "h+": this.getHours(), // hour
      "m+": this.getMinutes(), // minute
      "s+": this.getSeconds(), // second
      "q+": Math.floor((this.getMonth() + 3) / 3), // quarter
      "S": this.getMilliseconds()
      // millisecond
  }
  if (/(y+)/.test(format))
      format = format.replace(RegExp.$1, (this.getFullYear() + "")
          .substr(4 - RegExp.$1.length));
  for (var k in o)
      if (new RegExp("(" + k + ")").test(format))
          format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
  return format;
}

//打开连接
function openCate(categoryId){
	var url=$ctx+"/SiteIndex/category.htm?id="+encode64(categoryId)+"&parNav="+$olda.replace(/#nav/g, "");	           
    window.location.href=url;
}

function openArticle(articleId){
	var url=$ctx+"/SiteIndex/article.htm?id="+encode64(articleId)+"&parNav="+$olda.replace(/#nav/g, "");	           
    window.location.href=url;
}

//base64加密开始
var keyStr = "ABCDEFGHIJKLMNOP" + "QRSTUVWXYZabcdef" + "ghijklmnopqrstuv" + "wxyz0123456789+/" + "=";

function encode64(input) {
        var output = "";
        var chr1, chr2, chr3 = "";
        var enc1, enc2, enc3, enc4 = "";
        var i = 0;
        do {
                chr1 = input.charCodeAt(i++);
                chr2 = input.charCodeAt(i++);
                chr3 = input.charCodeAt(i++);
                enc1 = chr1 >> 2;
                enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
                enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
                enc4 = chr3 & 63;
                if (isNaN(chr2)) {
                        enc3 = enc4 = 64;
                } else if (isNaN(chr3)) {
                        enc4 = 64;
                }
                output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2)
                                + keyStr.charAt(enc3) + keyStr.charAt(enc4);
                chr1 = chr2 = chr3 = "";
                enc1 = enc2 = enc3 = enc4 = "";
        } while (i < input.length);

        return output;
}
// base64加密结束







